<?php

namespace IMooc;

class User
{
    public $id;
    public $name;
    public $mobile;
    public $regtime;

    protected $db;

    function __construct($id)
    {
        $this->db = mysql_connect('127.0.0.1', 'root', '');
        mysql_select_db('test', $this->db);
        $res = mysql_query("select * from user where id={$id} limit 1", $this->db);
        var_dump($res);
        $data = mysql_fetch_assoc($res);
        $this->id = $data['id'];
        $this->name = $data['name'];
        $this->mobile = $data['mobile'];
        $this->regtime = $data['regtime'];
    }

    function __destruct()
    {
        mysql_query("update user set name='{$this->name}',mobile='{$this->mobile}',regtime='{$this->regtime}' where id={$this->id} limit 1", $this->db);
        mysql_close($this->db);
    }
}